package mcweb.model.dao;

import java.sql.SQLException;
import java.util.List;

import mcweb.dto.DeliveryDTO;
import mcweb.dto.OrderDTO;
import mcweb.dto.OrderDetailDTO;

import org.springframework.orm.ibatis.SqlMapClientTemplate;

public class OrderDAOImpl implements IOrderDAO{
	
	private SqlMapClientTemplate template;
	
	public OrderDAOImpl() {}
	public OrderDAOImpl(SqlMapClientTemplate template) {
		this.template = template;
	}
	
	@Override
	public int selectSequenceNo() throws SQLException{
		return (Integer) template.queryForObject("order.selectSequenceNo");
	}
	
	@Override
	public Object addOrder(OrderDTO odto)throws SQLException{
		return template.insert("order.addOrder",odto);
	}

	@Override
	public void addOrderDetail(OrderDetailDTO o)throws SQLException{
		template.insert("order.addOrderDetail", o);
	}
	
	@Override
	public void addDelivery(DeliveryDTO d)throws SQLException{
		template.insert("order.addDelivery", d);
	}
	
	// kostafive
	@Override
	public List selectOrdersById(String id) throws SQLException {
		return template.queryForList("order.selectOrderId", id);
	}
	
	// kostafive
	@Override
	public List<OrderDetailDTO> selectOrderDetailByOrderId(int orderId) {
		return template.queryForList("order.selectOrderDetailByOrderId", orderId);
	}
	@Override
	public Object selectDeliveryByOrderId(int orderId) throws SQLException {
		return template.queryForObject("order.selectDeliveryByOrderId", orderId);
	}
	@Override
	public List<OrderDTO> selectOrders() throws SQLException {
		return template.queryForList("order.selectOrders");
	}
}
